﻿using BarManager.Core.ApplicationService.Interfaces;
using BarManager.Core.BusinessRules.Interfaces.Validator;
using BarManager.Core.DomainModel;
using BarManager.Core.DomainService;
using BarManager.Core.Entity;
using System.Collections.Generic;

namespace BarManager.Core.ApplicationService
{
    public class ZonaService : BaseApplicationService<Zona>, IZonaService
    {
        private IMesaService MesaService { get; set; }
        public ZonaService(IObjectContext context, IZonaRepository repository, IMesaService mesaService, IZonaValidator validator)
            : base(context,repository, validator)
        {
            this.MesaService = mesaService;
        }

        //- Zonas habilitadas que tengan mesas cargadas
        public IEnumerable<Zona> GetAllZonasHabilitadasContainsMesa()
        {
            return base.Find(x => x.Habilitada && x.Mesas.Count > 0);
        }
        
        public IEnumerable<Zona> GetAllZonasHabilitadasContainsMesasLibres()
        {
            List<Zona> zonas = new List<Zona>();
            IEnumerable<Mesa> mesas = MesaService.Find(x => x.Libre);

            //- Solo zonas con mesas libres
            foreach (var item in mesas)
            { if (item.Zona.Habilitada && !zonas.Contains(item.Zona)) zonas.Add(item.Zona); }

            return zonas;
        }       
    }
}
